class MyEx(Exception):
    pass


def get_inter_substr_between_same_letters(xstr):
    xlen = len(xstr)
    if xlen <= 0:
        return ''

    idx_l, idx_r = 0, xlen - 1
    found = False

    def locate_l():
        nonlocal idx_l
        curr, last = None, None
        while idx_l < xlen:
            if curr is None:
                curr = xstr[idx_l].lower()
            else:
                last = curr
                curr = xstr[idx_l].lower()
                if curr != last:
                    break
            idx_l += 1
        if idx_l >= idx_r:
            return ''

    def locate_r():
        nonlocal idx_r, found
        while idx_r >= 0:
            if xstr[idx_l - 1].lower() == xstr[idx_r].lower():
                idx_r -= 1
                found = True
                if idx_l >= idx_r:
                    return ''
            else:
                return False


    try:
        while True:
            locate_l()
            while True:
                res = locate_r()
                if res:
                    break
                if found:
                    raise MyEx()
            idx_l += 1
    except MyEx as ex:
        return xstr[idx_l:idx_r + 1]


if '__main__' == __name__:
    tests = [
        'Good',
        'a',
        'sstress',
        '',
        'sTreSS',
        'Goabcod',
        'Goabcoood',
        'Gooabcod',
        'Gooabcood',
        'Goooabcoood',
        'asdf',
        'BBRR',
        'adca',
        'address',
        'address again',
    ]
    for xtest in tests:
        print(f'|{xtest}| => |{get_inter_substr_between_same_letters(xtest)}|')
